//
//  HomePageViewController.m
//  LastTemp
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "HomePageViewController.h"
#import "ButtonViewController.h"
#import "HomePage.h"
#import "UIImageView+WebCache.h"
#import "NetWorkingTool.h"
#import "SDCycleScrollView.h"
#import "MyTableViewCell.h"
#import "HomePageHeadView.h"
#import "HomePageFootView.h"
#import "MaterViewController.h"
#import "MVPlayViewController.h"
#import "drawerView.h"
#import "UMSocial.h"
#import "UMSocialSnsService.h"
#import "bofangViewController.h"
#import "BassModel.h"
#import "MyCollectionViewCell.h"
#import "AFSoundManager.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface HomePageViewController ()<SDCycleScrollViewDelegate>
@property(nonatomic,retain)NSMutableArray *scrollerModelArr;
@property(nonatomic,retain)NSMutableArray *scrollerImageArr;
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)NSMutableArray *tableModelArr;
@property(nonatomic,retain)HomePageHeadView *head;
@property(nonatomic,retain)HomePageFootView *foot;
@property(nonatomic,retain)NSMutableArray *giveArr;
@property(nonatomic,retain)NSMutableArray *MVArr;
@property(nonatomic,retain)NSMutableArray *firstArr;
@property(nonatomic,assign)NSInteger temp;
@property(nonatomic,retain)SDCycleScrollView *scrollView;
@property(nonatomic,retain)NSMutableArray *playHomeArr;
@property(nonatomic,retain)UIImageView *imageView;


@property(nonatomic,assign)NSInteger myWidth;
@property(nonatomic,assign)NSInteger myHeight;

@property(nonatomic,retain)UIView *onceView;


@end

@implementation HomePageViewController

- (void)dealloc
{
    [_onceView release];
    [_imageView release];
    [_scrollView release];
    [_playHomeArr release];
    [_scrollerImageArr release];
    [_tableView release];
    [_tableModelArr release];
    [_head release];
    [_foot release];
    [_giveArr release];
    [_MVArr release];
    [_firstArr release];
    [_scrollerModelArr release];
    [super dealloc];
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.scrollerModelArr = [NSMutableArray array];
        self.scrollerImageArr = [NSMutableArray array];
        self.tableModelArr = [NSMutableArray array];
        self.giveArr = [NSMutableArray array];
        self.MVArr = [NSMutableArray array];
        self.firstArr = [NSMutableArray array];
        [AVSingleton shareSingleton].delegatePlay = self;
        self.myHeight = 1;
    }
    [self dataHotSong];
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];


    [self addTableView];
    
    
    self.onceView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:self.onceView];
    [_onceView release];
    
    
    self.imageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.onceView addSubview:self.imageView];
    [_imageView release];
    self.imageView.image = [UIImage imageNamed:@"welcom"];
    
    UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(WIDTH/2, 100, 30, 30)];
    [activity setCenter:CGPointMake(self.view.frame.size.width / 2, (self.view.frame.size.height - 113) / 2)]; // 指定进度轮中心点
    [activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [self.imageView addSubview:activity];
    [activity startAnimating];
    [activity release];
    
   
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)showMessage:(NSString *)message
{
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height/2-32.5,WIDTH, 65)];
    view2.backgroundColor = [UIColor whiteColor];
    view2.alpha = 0.8;
    UILabel *label = [[UILabel alloc] init];
    label.text = message;
    label.textAlignment = NSTextAlignmentCenter;
    label.frame = CGRectMake(0, view2.frame.size.height/2-20, WIDTH, 40);
    [view2 addSubview:label];
    label.textAlignment = NSTextAlignmentCenter;
    
    [self.view addSubview:view2];
    [UIView animateWithDuration:5 animations:^{
        view2.alpha = 0;
    } completion:^(BOOL finished) {
        [view2 removeFromSuperview];
    }];
    
    [label release];
    [view2 release];
}

#pragma mark 轮播区
- (void)addScrollerView
{
    self.scrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    self.scrollView.delegate = self;
    self.scrollView.dotColor = [UIColor blackColor];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.scrollView.imageURLsGroup = self.scrollerImageArr;
    });

}

#pragma mark 轮播区点击方法
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{

    self.temp = index;
    [self pushNextPage];

}

- (void)pushNextPage
{
    MaterViewController *mater = [[MaterViewController alloc] init];
    HomePage *home = self.scrollerModelArr[self.temp];
    mater.pageId1 = home.content_id;
    mater.temp = 1;
    [self.navigationController pushViewController:mater animated:YES];
    [mater release];
}


#pragma mark 添加tableView
-(void)addTableView
{
    UIImageView *tableImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:tableImageView];
    [tableImageView release];
    tableImageView.image = [UIImage imageNamed:@"picSky"];
    tableImageView.alpha = 0.7;
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT-64-49) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.rowHeight = 70;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    
    
    
    
    self.head = [[HomePageHeadView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, 330)];
    UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonOne.frame = CGRectMake(15, 210, self.view.frame.size.width/3-40, 80);
    [self.head addSubview:buttonOne];
    buttonOne.tag = 9000;

    [buttonOne addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonTwo.frame = CGRectMake(WIDTH/3+15, 210, WIDTH/3-40, 80);
    [self.head addSubview:buttonTwo];
    buttonTwo.tag = 9001;

    [buttonTwo addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];

    UIButton *buttonThree = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonThree.frame = CGRectMake((WIDTH/3)*2+15, 210, WIDTH/3-40, 80);
    [self.head addSubview:buttonThree];
    buttonThree.tag = 9002;

    [buttonThree addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
    
       
  

    self.head.labelHot.backgroundColor = [UIColor colorWithRed:108/255.0 green:108/255.0 blue:108/255.0 alpha:1];
    self.head.labelHot.text = @"  | 热门歌曲";
    self.head.labelHot.font = [UIFont systemFontOfSize:17];
    self.head.labelHot.textColor = [UIColor whiteColor];
    
    self.head.labelGive.backgroundColor = [UIColor colorWithRed:108/255.0 green:108/255.0 blue:108/255.0 alpha:1];
    self.head.labelGive.textColor = [UIColor whiteColor];
    
    self.tableView.tableHeaderView = self.head;
    self.scrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, self.head.frame.size.width, 180) imagesGroup:nil];
    self.scrollView.autoScrollTimeInterval = 5;
    [self.head addSubview:self.scrollView];
    [_scrollView release];
    self.foot = [[HomePageFootView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, 400)];
    self.tableView.tableFooterView = self.foot;
    [self addCollectionView];
    
    
    
    UILabel *footLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 240, WIDTH, 20)];
    [self.foot addSubview:footLabel];
    [footLabel release];
    footLabel.backgroundColor = [UIColor colorWithRed:108/255.0 green:108/255.0 blue:108/255.0 alpha:1];
    footLabel.text = @"  | 新歌首发";
    footLabel.textColor = [UIColor whiteColor];
    
    [self.foot.buttonOne addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
    self.foot.buttonOne.tag = 8000;
    
    
    [self.foot.buttonTwo addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
    self.foot.buttonTwo.tag = 8001;
    
    
    
    [self.foot.buttonThree addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
    self.foot.buttonThree.tag = 8002;
    
    
    
    

    
    
    
}

#pragma mark tableView 必需实现的两个方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger num = 1;
    if (self.giveArr.count > 0 && num == 1) {
        [self buttonAgain];
        num = 0;
    }
    if (self.scrollerModelArr > 0) {
        [self addScrollerView];
        
    }
    if (self.giveArr.count > 0 && self.scrollerModelArr > 0) {
        [self.onceView removeFromSuperview];
        if (self.myHeight == 1) {
            if ([AVSingleton shareSingleton].internetNum1 == 0) {
                
                [self showMessage:@"您现在使用的网络未知,请注意安全"];
            } else if ([AVSingleton shareSingleton].internetNum1 == 1) {
                
                [self showMessage:@"您现在使用的是手机自带网络,请注意流量"];
            } else if ([AVSingleton shareSingleton].internetNum1 == 2) {
                
                [self showMessage:@"您现在使用的是WiFi网络,请放心使用"];
            }
            self.myHeight = 2;
        }
   
    }
    
    
    return self.tableModelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (cell == nil) {
        cell = [[[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
    }
    HomePage *home = self.tableModelArr[indexPath.row];
   
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.nameLabel.text = home.song_name;
    cell.wordLabel.text = home.singer_name;
    NSURL *url = [NSURL URLWithString:home.singer_pic_url];
    [cell.myImageView sd_setImageWithURL:url];
    cell.backgroundColor = [UIColor clearColor];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    self.playHomeArr = [NSMutableArray array];
    HomePage *home = self.tableModelArr[indexPath.row];
    NSLog(@"%@",home.url);
   
    
    if ([AVSingleton shareSingleton].fromNum != indexPath.row || [AVSingleton shareSingleton].fromNum != 0) {
        [[AFSoundManager sharedManager] stop];
    }
    [[AFSoundManager sharedManager] startStreamingRemoteAudioFromURL:home.url andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
        [AVSingleton shareSingleton].percentage = percentage;
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"mm:ss"];
        NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
        [AVSingleton shareSingleton].beginTime = [formatter stringFromDate:elapsedTimeDate];
        
        NSDate *timeRemainingDate = [NSDate dateWithTimeIntervalSince1970:timeRemaining];
        [AVSingleton shareSingleton].time = [formatter stringFromDate:timeRemainingDate];
        
    
    }];
    
    for (NSInteger i = 0; i < self.tableModelArr.count; i ++) {
        HomePage *home1 = self.tableModelArr[i];
        BassModel *base = [[BassModel alloc] init];
        base.name1 = home1.song_name;
        base.singerName1 = home1.singer_name;
        base.url1 = home1.url;
        base.shareUrl = home1.shareUrl;
        base.picURL = home1.singer_pic_url;
        [self.playHomeArr addObject:base];
        [base release];
    }
    
    [AVSingleton shareSingleton].fromArr = self.playHomeArr;
    [AVSingleton shareSingleton].fromNum = indexPath.row;
    [AVSingleton shareSingleton].myBool = YES;
//      [AVSingleton shareSingleton].playNum = 1;
//     [AVSingleton shareSingleton].playNum2 = 1;
    bofangViewController *play = [[bofangViewController alloc] init];
//    play.allArr = [AVSingleton shareSingleton].fromArr;
    [self presentViewController:play animated:YES completion:^{
        
    }];
    [play release];
}


- (void)click1:(UIButton *)button
{
    if (button.tag == 9000) {
        MaterViewController *mater = [[MaterViewController alloc] init];
        HomePage *home = self.giveArr[0];
        mater.pageId2 = home.resid;
        mater.temp = 2;
        [self.navigationController pushViewController:mater animated:YES];
        [mater release];
    } else if (button.tag == 9001) {
        MaterViewController *mater = [[MaterViewController alloc] init];
        HomePage *home = self.giveArr[1];
        mater.pageId2 = home.resid;
        mater.temp = 2;
        [self.navigationController pushViewController:mater animated:YES];
        [mater release];
    } else if (button.tag == 9002) {
        MaterViewController *mater = [[MaterViewController alloc] init];
        HomePage *home = self.giveArr[2];
        mater.pageId2 = home.resid;
        mater.temp = 2;
        [self.navigationController pushViewController:mater animated:YES];
        [mater release];
    } else if (button.tag == 8000) {
        MaterViewController *mater = [[MaterViewController alloc] init];
        HomePage *home = self.firstArr[0];
        mater.pageId3 = home.resid;
        mater.temp = 3;
        [self.navigationController pushViewController:mater animated:YES];
         [mater release];
    } else if (button.tag == 8001) {
        MaterViewController *mater = [[MaterViewController alloc] init];
        HomePage *home = self.firstArr[1];
        mater.pageId3 = home.resid;
        mater.temp = 3;
        [self.navigationController pushViewController:mater animated:YES];
         [mater release];
    } else if (button.tag == 8002) {
        MaterViewController *mater = [[MaterViewController alloc] init];
        HomePage *home = self.firstArr[2];
        mater.pageId3 = home.resid;
        mater.temp = 3;
        [self.navigationController pushViewController:mater animated:YES];
         [mater release];
    } else if (button.tag == 7000) {
        MVPlayViewController *mv = [[MVPlayViewController alloc] init];
        HomePage *home = self.MVArr[0];
        mv.mvPassURL = home.mv_url;
        [self.navigationController pushViewController:mv animated:YES];
         [mv release];
    } else if (button.tag == 7001) {
        MVPlayViewController *mv = [[MVPlayViewController alloc] init];
        HomePage *home = self.MVArr[1];
        mv.mvPassURL = home.mv_url;
        [self.navigationController pushViewController:mv animated:YES];
        [mv release];
    } else if (button.tag == 7002) {
        MVPlayViewController *mv = [[MVPlayViewController alloc] init];
        HomePage *home = self.MVArr[2];
        mv.mvPassURL = home.mv_url;
        [self.navigationController pushViewController:mv animated:YES];
        [mv release];
    } else if (button.tag == 7003) {
        MVPlayViewController *mv = [[MVPlayViewController alloc] init];
        HomePage *home = self.MVArr[3];
        mv.mvPassURL = home.mv_url;
        [self.navigationController pushViewController:mv animated:YES];
        [mv release];
    }
    
    
}
    
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark 数据解析

- (void)dataHotSong
{
    if ([AVSingleton shareSingleton].internetNum == 1) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您现在没有网络,请检查网络!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        [alert release];
        
    } else {
    [NetWorkingTool netWorkingToolStr:@"http://iting.music.189.cn:9200/iting2/imusic/V2?ids=banner_4,newsongalbum_3,selectedmv_4,recommendMusicPlayList_3,hotsong_10&protocolCode=2.0&method=get_gate_module_ios&sid=234472872&networkType=wifi&serviceCode=100&sessionId=83356C7DD4CDA5C8EE072C41746AA3A6&format=json&timestamp=20150424084717&sign=d68ad3aab1dd31af84e3e6a3da6dfb4e&imsi=87D618C0-A675-458D-BB55-BED13C712771&company=&appChannelCode=10000000&appVerCode=2.000.004" block:^(id result) {
        NSMutableDictionary *dic = result;
        // 轮播数据解析
        NSMutableArray *dataArr = dic[@"banner"][@"data"];
        for (NSInteger i = 0; i < dataArr.count; i ++) {
            HomePage *home = [[HomePage alloc] init];
            [home setValuesForKeysWithDictionary:dataArr[i]];
            [self.scrollerModelArr addObject:home];
            NSURL *url = [NSURL URLWithString:home.pic_url];
           
            [self.scrollerImageArr addObject:url];
            NSString *str = [home.url substringToIndex:10];
            
            if ([str isEqualToString:@"http://wap"]) {
                [self.scrollerImageArr removeLastObject];
            }
            [home release];
        }
        
        
        // 热歌数据解析
        NSMutableArray *hotSongArr = dic[@"hotsong"][@"data"];
        for (NSInteger i = 0; i < hotSongArr.count; i++) {
            HomePage *home = [[HomePage alloc] init];
            [home setValuesForKeysWithDictionary:hotSongArr[i]];
            NSMutableDictionary *dic = hotSongArr[i][@"qqInfo"];
            NSMutableArray *qq_url_listArr = dic[@"qq_url_list"];
            NSMutableDictionary *dic1 = [qq_url_listArr firstObject];
            [home setValuesForKeysWithDictionary:dic1];
            [self.tableModelArr addObject:home];
            [home release];
        }
        
        
        // 推荐歌单数据解析
        NSMutableArray *scrolArr = dic[@"recommendMusicPlayList"][@"data"];
        for (NSInteger i = 0; i < scrolArr.count; i++) {
            HomePage *home = [[HomePage alloc] init];
            [home setValuesForKeysWithDictionary:scrolArr[i]];
            [self.giveArr addObject:home];
            [home release];
            
        }
        
        
        // MV 数据解析
        NSMutableArray *selectedmvArr = dic[@"selectedmv"][@"data"];
        for (NSInteger i = 0; i < selectedmvArr.count; i++) {
            HomePage *home = [[HomePage alloc] init];
            [home setValuesForKeysWithDictionary:selectedmvArr[i]];
            NSMutableArray *mv_url_listArr = selectedmvArr[i][@"mv_url_list"];
            NSMutableDictionary *dic = [mv_url_listArr lastObject];
            [home setValuesForKeysWithDictionary:dic];
            [self.MVArr addObject:home];
            [home release];
        }
        
        
        // 新歌数据解析
        NSMutableArray *theNewSongAlbumArr = dic[@"theNewSongAlbum"][@"data"];
        for (NSInteger i = 0; i < theNewSongAlbumArr.count; i++) {
            HomePage *home = [[HomePage alloc] init];
            [home setValuesForKeysWithDictionary:theNewSongAlbumArr[i]];
            [self.firstArr addObject:home];
            [home release];
        }
        
        
        [self.tableView reloadData];
        UICollectionView *co = (UICollectionView *)[self.foot viewWithTag:900];
        [co reloadData];
    }];
    }
    
}
#pragma mark headView 和footView的设置和铺设
- (void)buttonAgain
{
    if (self.giveArr.count > 0) {
        for (NSInteger i = 0; i < self.giveArr.count; i++) {
            HomePage *home = self.giveArr[i];
            if (i == 0) {
                NSURL *url = [NSURL URLWithString:home.pic_url];
                [self.head.imageViewOne sd_setImageWithURL:url];
                self.head.labelOne.text = home.songlistname;
            } else if (i == 1) {
                NSURL *url = [NSURL URLWithString:home.pic_url];
                [self.head.imageViewTwo sd_setImageWithURL:url];
                self.head.labelTwo.text = home.songlistname;
            } else if (i == 2) {
                NSURL *url = [NSURL URLWithString:home.pic_url];
                [self.head.imageViewThree sd_setImageWithURL:url];
                self.head.labelThree.text = home.songlistname;
            }
        }
        
    }
    
    
    if (self.firstArr > 0) {
        for (NSInteger i = 0; i < self.firstArr.count ; i ++) {
            HomePage *home = self.firstArr[i];
            if (i == 0) {
                NSURL *url = [NSURL URLWithString:home.pic_url];
                [self.foot.imageViewOne sd_setImageWithURL:url];
                self.foot.labelOne.text = home.name;
            } else if (i == 1) {
                NSURL *url = [NSURL URLWithString:home.pic_url];
                [self.foot.imageViewTwo sd_setImageWithURL:url];
                self.foot.labelTwo.text = home.name;
            } else if (i == 2) {
                NSURL *url = [NSURL URLWithString:home.pic_url];
                [self.foot.imageViewThree sd_setImageWithURL:url];
                self.foot.labelThree.text = home.name;
            }
        }
    }
}
  
- (void)presentPlyer
{
    bofangViewController *play = [[bofangViewController alloc] init];
    [self presentViewController:play animated:YES completion:^{
        
    }];
    [play release];
}

- (void)addCollectionView
{
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置item的大小
    

    
    flowLayout.itemSize = CGSizeMake(WIDTH/3.125, WIDTH/3.75);
    // 设置最小的行间距
    flowLayout.minimumLineSpacing = 1;

    flowLayout.minimumInteritemSpacing = 1;

    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;

    if (WIDTH==320) {
         flowLayout.sectionInset = UIEdgeInsetsMake(50, 40, 50, 40);
    } else {
         flowLayout.sectionInset = UIEdgeInsetsMake(30, 40, 30, 40);
    }
   
    
    
    UICollectionView *myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 270) collectionViewLayout:flowLayout];
    
    myCollectionView.backgroundColor = [UIColor clearColor];
    
    myCollectionView.dataSource = self;
    myCollectionView.delegate = self;
    [self.foot addSubview:myCollectionView];
    [myCollectionView release];
    myCollectionView.tag = 900;
    
    
    UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 20)];
    [myCollectionView addSubview:topLabel];
    [topLabel release];
    topLabel.backgroundColor = [UIColor colorWithRed:108/255.0 green:108/255.0 blue:108/255.0 alpha:1];
    topLabel.text =  @"  | 热播MV";
    topLabel.textColor = [UIColor whiteColor];
    
    
   
#pragma mark CollectionView只能采用注册的方式生成cell
    // 注册cell
    
    [myCollectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"reuse2"];
}


#pragma mark 协议里有两个必须实现的协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [self.MVArr count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse2" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor clearColor];

    HomePage *home = self.MVArr[indexPath.row];
    cell.myLabel.text = home.title;
    NSURL *url = [NSURL URLWithString:home.pic_url];
    [cell.myImageView sd_setImageWithURL:url];
    
    
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([AVSingleton shareSingleton].myBool == YES) {
        [[AFSoundManager sharedManager] pause];
    }
    MVPlayViewController *mv = [[MVPlayViewController alloc] init];
    HomePage *home = self.MVArr[indexPath.row];
    mv.mvPassURL = home.mv_url;
    [self presentViewController:mv animated:YES completion:^{
        
    }];
    [mv release];
}



@end
